package maze.net.server;

import java.io.IOException;
import java.net.Socket;

import maze.net.MessageType;
import maze.net.SGMPException;
import maze.net.SGMPInputStream;
import maze.pojo.Action;

public class SGMPServerInputStream extends SGMPInputStream {

	public SGMPServerInputStream(Socket socket) throws IOException {
		super(socket.getInputStream());
	}
	
	public void waitACK() throws IOException, SGMPException {
		MessageType type = readHeader();
		if(type != MessageType.C_ACK) {
			throw new SGMPException("Expect C_ACK, but actual " + type);
		}
	}
	
	public Action readAction() throws IOException, SGMPException {
		MessageType type = readHeader();
		if(type != MessageType.C_Action) {
			throw new SGMPException("Expect C_Action, but actual " + type);
		}
		return Action.getAction(readByte());
	}
}
